/* (PARI) _R. J. Cano_, from Sept 21 to Oct 04 2015. - Script begins here.
*
*  On-Line source & possible updates for this file:
   Please Visit, http://oeis.org/w/images/0/04/Sol_probleme_125_.txt
*
*  The present material is released under the "End user" license agreement.
*  (Please see: http://oeis.org/wiki/The_OEIS_End-User_License_Agreement for details)
*/

/* Purpose:
 *     Aid routines intended to search solutions related to
 *     http://www.nymphomath.ch/turing/probleme.php?id=125
*/

/* Notes: 1) By ignoring himself another better way of performing the required searches,
 *           the present code can be considered honestly the best that author was able
 *           to achieve by reviewing the issued problem countless times -ad libitum- during
 *           his idle hours.
 * 
 *        2) The best performance for this code depends on its compilation
 *           by translating it with GP2C.
*/

/* Warning:
 *   The successful execution of this script might require to allocate extra memory.
 *   It is strongly suggested to do that at the OS prompt invocation of gp with the
 *   -s option.
*/

cubesPerLayer(x,y,z,l)=2*(x*y+x*z+y*z+2*(l-1)*(x+y+z-2)+4*binomial(l,2));

getUpperLimit01_3D(n,a=1)=ceil((a*n-2)/4); /* Should we try?, Sizes: How many cubes? */

getUpperLimit02_3D(n,a=1)=ceil(sqrt(a*n-1)/2-1); /* Should we try?, How many layers? */

C3(n,a=1)={
  my(m=a*n,s=0,u1=getUpperLimit01_3D(n,a),u2=getUpperLimit02_3D(n,a),t);
  forvec(y=vector(3,j,[1,u1]),
    for(k=1,u2,
      t=cubesPerLayer(y[1],y[2],y[3],k);
      if(t>=m,
        s+=!(m-t);
        break;
      )
    );
  ,1);
  s
}

/* 2D Version */

squaresPerLayer(x,y,l)=2*(x+y+2*(l-1));

getUpperLimit01_2D(n,a=1)=ceil(a*n/2-1); /* Should we try?, Sizes: How many squares? */

getUpperLimit02_2D(n,a=1)=ceil(a*n/4+1); /* Should we try?, How many layers? */

C2(n,a=1)={
  my(m=a*n,s=0,u1=getUpperLimit01_2D(n,a),u2=getUpperLimit02_2D(n,a),t);
  forvec(y=vector(2,j,[1,u1]),
    t=squaresPerLayer(y[1],y[2],1);
    if(t>=m,
      s+=!(m-t);
      break
    );
    for(k=2,u2,
      t=squaresPerLayer(y[1],y[2],k);
      if(t>=m,
	s+=!(m-t);
        break
      )
    )
  ,1);
  s
}

/* Number of weakly increasing combinations that can be
 * made from x elements by taking them in groups of n.*/

binomialbi(x,n)=sum(k=1,n,binomial(n-1,k-1)*binomial(x,k));

/* kth differences of a vector. */

vecDiff(v,k=1)={my(w=vector(#v-k,j,((-1)^(k%2))*sum(i=0,k,((-1)^(i%2))*binomial(k,i)*v[j+i])));if(type(v)==type(w),w,w~)}

/* Script ends here. */

/* Proof #1 begins here: */

proof=vector(99,i,C2(i,2)); /* Sample vector containing the first terms of the sequence
                               for the number of rectangles that requires 2*n squares in
                               one of their layers.
                                
                               Those terms here mentioned indeed are binomial(x,2), repeated. */

print("\"The number of rectangles that requires 2*n squares in one of their layers.\" (first 99 terms): "proof);
                                
/* Proof #1 ends here. */

/*
* 
  Proof #2 begins here: "Trouver la plus petite valeur de n pour laquelle C(n) = 100."

n=1;
y=0;
results=List();
while(y!=100,y=C3(n);listput(results,y);n++);  
time = 3h, 39min, 35,649 ms.
n--;
print("n="n);
n=1662
? checkAnswer=C3(1662);
time = 33,746 ms.
print(checkAnswer);
100

  Proof #2 ends here. (Note: Proof executed on a 32 Bits machine, 1.66Ghz Intel Atom processor + 1Gb of RAM, Slackware GNU Linux 14.1, PARI 2.7.4 and GP2C 0.0.9pl3)
*
 */

/*
*
  Appendix to Proof #2 begins here.

print(results);
List([0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 2, 0, 0, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 3, 0, 2, 0, 3, 0, 0, 0, 4, 0, 3, 0, 3, 0, 2, 0, 3, 0, 2, 0, 5, 0, 1, 0, 4, 0, 4, 0, 5, 0, 1, 0, 5, 0, 3, 0, 4, 0, 3, 0, 5, 0, 3, 0, 7, 0, 2, 0, 4, 0, 5, 0, 5, 0, 2, 0, 7, 0, 6, 0, 6, 0, 3, 0, 6, 0, 3, 0, 8, 0, 3, 0, 6, 0, 7, 0, 6, 0, 2, 0, 8, 0, 6, 0, 7, 0, 4, 0, 8, 0, 5, 0, 9, 0, 4, 0, 5, 0, 8, 0, 8, 0, 2, 0, 11, 0, 8, 0, 9, 0, 6, 0, 6, 0, 6, 0, 10, 0, 3, 0, 9, 0, 9, 0, 11, 0, 3, 0, 11, 0, 9, 0, 6, 0, 7, 0, 9, 0, 7, 0, 12, 0, 5, 0, 9, 0, 9, 0, 11, 0, 4, 0, 13, 0, 11, 0, 9, 0, 8, 0, 9, 0, 7, 0, 14, 0, 5, 0, 11, 0, 13, 0, 12, 0, 3, 0, 11, 0, 11, 0, 12, 0, 7, 0, 14, 0, 9, 0, 15, 0, 7, 0, 7, 0, 15, 0, 10, 0, 6, 0, 17, 0, 12, 0, 12, 0, 7, 0, 12, 0, 9, 0, 16, 0, 9, 0, 12, 0, 15, 0, 15, 0, 4, 0, 17, 0, 13, 0, 11, 0, 8, 0, 13, 0, 13, 0, 18, 0, 9, 0, 11, 0, 15, 0, 15, 0, 5, 0, 20, 0, 16, 0, 14, 0, 12, 0, 12, 0, 9, 0, 18, 0, 8, 0, 16, 0, 17, 0, 17, 0, 8, 0, 13, 0, 18, 0, 13, 0, 12, 0, 19, 0, 12, 0, 23, 0, 7, 0, 14, 0, 19, 0, 15, 0, 6, 0, 21, 0, 19, 0, 14, 0, 12, 0, 17, 0, 13, 0, 21, 0, 10, 0, 16, 0, 21, 0, 17, 0, 8, 0, 20, 0, 18, 0, 19, 0, 12, 0, 19, 0, 14, 0, 21, 0, 13, 0, 10, 0, 21, 0, 22, 0, 6, 0, 28, 0, 21, 0, 18, 0, 14, 0, 15, 0, 17, 0, 19, 0, 12, 0, 19, 0, 23, 0, 24, 0, 8, 0, 23, 0, 19, 0, 15, 0, 16, 0, 22, 0, 18, 0, 28, 0, 9, 0, 15, 0, 22, 0, 20, 0, 10, 0, 26, 0, 27, 0, 20, 0, 13, 0, 19, 0, 15, 0, 29, 0, 14, 0, 21, 0, 27, 0, 20, 0, 13, 0, 21, 0, 24, 0, 16, 0, 16, 0, 27, 0, 12, 0, 29, 0, 14, 0, 19, 0, 30, 0, 24, 0, 10, 0, 30, 0, 26, 0, 23, 0, 16, 0, 20, 0, 20, 0, 25, 0, 15, 0, 19, 0, 29, 0, 26, 0, 9, 0, 29, 0, 26, 0, 23, 0, 16, 0, 27, 0, 23, 0, 29, 0, 16, 0, 19, 0, 24, 0, 28, 0, 11, 0, 35, 0, 29, 0, 19, 0, 22, 0, 16, 0, 20, 0, 32, 0, 15, 0, 29, 0, 31, 0, 30, 0, 11, 0, 24, 0, 32, 0, 18, 0, 19, 0, 31, 0, 24, 0, 35, 0, 16, 0, 18, 0, 32, 0, 28, 0, 12, 0, 35, 0, 28, 0, 28, 0, 20, 0, 29, 0, 21, 0, 33, 0, 18, 0, 20, 0, 38, 0, 27, 0, 13, 0, 30, 0, 31, 0, 28, 0, 17, 0, 34, 0, 22, 0, 34, 0, 22, 0, 24, 0, 35, 0, 23, 0, 12, 0, 42, 0, 34, 0, 27, 0, 23, 0, 24, 0, 25, 0, 33, 0, 20, 0, 29, 0, 33, 0, 39, 0, 12, 0, 29, 0, 34, 0, 24, 0, 28, 0, 30, 0, 26, 0, 40, 0, 15, 0, 22, 0, 36, 0, 35, 0, 18, 0, 41, 0, 42, 0, 22, 0, 23, 0, 30, 0, 24, 0, 41, 0, 16, 0, 33, 0, 35, 0, 33, 0, 16, 0, 33, 0, 36, 0, 29, 0, 23, 0, 40, 0, 30, 0, 38, 0, 23, 0, 18, 0, 46, 0, 32, 0, 14, 0, 44, 0, 39, 0, 36, 0, 22, 0, 31, 0, 24, 0, 37, 0, 26, 0, 30, 0, 43, 0, 37, 0, 17, 0, 42, 0, 32, 0, 26, 0, 25, 0, 35, 0, 34, 0, 41, 0, 26, 0, 26, 0, 41, 0, 41, 0, 14, 0, 48, 0, 43, 0, 29, 0, 24, 0, 29, 0, 32, 0, 43, 0, 23, 0, 39, 0, 44, 0, 35, 0, 16, 0, 34, 0, 48, 0, 31, 0, 29, 0, 44, 0, 23, 0, 52, 0, 24, 0, 25, 0, 46, 0, 34, 0, 23, 0, 41, 0, 41, 0, 35, 0, 27, 0, 40, 0, 29, 0, 49, 0, 20, 0, 36, 0, 53, 0, 44, 0, 17, 0, 38, 0, 43, 0, 27, 0, 28, 0, 45, 0, 38, 0, 44, 0, 33, 0, 23, 0, 43, 0, 41, 0, 16, 0, 60, 0, 46, 0, 40, 0, 31, 0, 29, 0, 37, 0, 40, 0, 24, 0, 36, 0, 48, 0, 48, 0, 18, 0, 46, 0, 47, 0, 35, 0, 35, 0, 45, 0, 34, 0, 47, 0, 27, 0, 38, 0, 45, 0, 40, 0, 20, 0, 52, 0, 53, 0, 29, 0, 32, 0, 37, 0, 36, 0, 59, 0, 27, 0, 34, 0, 53, 0, 42, 0, 22, 0, 41, 0, 50, 0, 41, 0, 24, 0, 54, 0, 34, 0, 55, 0, 26, 0, 28, 0, 61, 0, 44, 0, 24, 0, 59, 0, 52, 0, 40, 0, 34, 0, 41, 0, 28, 0, 41, 0, 35, 0, 41, 0, 55, 0, 49, 0, 20, 0, 45, 0, 50, 0, 37, 0, 37, 0, 50, 0, 46, 0, 54, 0, 25, 0, 31, 0, 54, 0, 55, 0, 20, 0, 61, 0, 55, 0, 38, 0, 40, 0, 32, 0, 40, 0, 55, 0, 30, 0, 51, 0, 50, 0, 51, 0, 23, 0, 46, 0, 63, 0, 30, 0, 32, 0, 50, 0, 37, 0, 67, 0, 30, 0, 41, 0, 58, 0, 49, 0, 22, 0, 61, 0, 58, 0, 39, 0, 33, 0, 49, 0, 43, 0, 46, 0, 37, 0, 36, 0, 70, 0, 49, 0, 24, 0, 52, 0, 44, 0, 53, 0, 35, 0, 59, 0, 41, 0, 62, 0, 38, 0, 27, 0, 59, 0, 50, 0, 26, 0, 68, 0, 58, 0, 41, 0, 34, 0, 42, 0, 47, 0, 57, 0, 35, 0, 52, 0, 65, 0, 55, 0, 21, 0, 53, 0, 59, 0, 33, 0, 46, 0, 56, 0, 41, 0, 62, 0, 33, 0, 40, 0, 60, 0, 58, 0, 25, 0, 60, 0, 73, 0, 48, 0, 42, 0, 49, 0, 41, 0, 68, 0, 28, 0, 44, 0, 60, 0, 53, 0, 34, 0, 52, 0, 63, 0, 39, 0, 33, 0, 71, 0, 43, 0, 66, 0, 37, 0, 36, 0, 70, 0, 49, 0, 26, 0, 75, 0, 64, 0, 54, 0, 38, 0, 39, 0, 51, 0, 61, 0, 40, 0, 47, 0, 68, 0, 59, 0, 22, 0, 63, 0, 66, 0, 51, 0, 42, 0, 60, 0, 54, 0, 51, 0, 40, 0, 36, 0, 68, 0, 68, 0, 26, 0, 76, 0, 58, 0, 45, 0, 51, 0, 47, 0, 38, 0, 65, 0, 39, 0, 59, 0, 70, 0, 63, 0, 27, 0, 51, 0, 78, 0, 46, 0, 40, 0, 64, 0, 53, 0, 79, 0, 38, 0, 42, 0, 73, 0, 45, 0, 30, 0, 68, 0, 71, 0, 53, 0, 37, 0, 69, 0, 36, 0, 71, 0, 41, 0, 50, 0, 85, 0, 61, 0, 35, 0, 55, 0, 67, 0, 42, 0, 44, 0, 66, 0, 56, 0, 71, 0, 39, 0, 42, 0, 71, 0, 67, 0, 28, 0, 91, 0, 67, 0, 46, 0, 44, 0, 52, 0, 65, 0, 66, 0, 41, 0, 54, 0, 64, 0, 75, 0, 28, 0, 60, 0, 72, 0, 55, 0, 55, 0, 61, 0, 51, 0, 73, 0, 44, 0, 42, 0, 75, 0, 59, 0, 26, 0, 75, 0, 88, 0, 52, 0, 52, 0, 57, 0, 48, 0, 79, 0, 41, 0, 67, 0, 76, 0, 61, 0, 34, 0, 59, 0, 65, 0, 46, 0, 47, 0, 84, 0, 59, 0, 77, 0, 42, 0, 34, 0, 89, 0, 66, 0, 31, 0, 85, 0, 77, 0, 71, 0, 39, 0, 55, 0, 53, 0, 67, 0, 55, 0, 49, 0, 83, 0, 67, 0, 33, 0, 76, 0, 77, 0, 52, 0, 51, 0, 73, 0, 56, 0, 71, 0, 40, 0, 56, 0, 79, 0, 77, 0, 30, 0, 78, 0, 80, 0, 44, 0, 58, 0, 58, 0, 63, 0, 81, 0, 37, 0, 68, 0, 81, 0, 76, 0, 32, 0, 69, 0, 92, 0, 46, 0, 52, 0, 75, 0, 48, 0, 90, 0, 45, 0, 48, 0, 73, 0, 73, 0, 47, 0, 86, 0, 87, 0, 58, 0, 51, 0, 54, 0, 54, 0, 73, 0, 49, 0, 63, 0, 103, 0, 68, 0, 28, 0, 69, 0, 77, 0, 69, 0, 44, 0, 86, 0, 67, 0, 71, 0, 59, 0, 44, 0, 87, 0, 67, 0, 30, 0, 104, 0, 73, 0, 63, 0, 58, 0, 57, 0, 69, 0, 83, 0, 50, 0, 55, 0, 90, 0, 91, 0, 39, 0, 70, 0, 78, 0, 50, 0, 50, 0, 80, 0, 59, 0, 88, 0, 48, 0, 61, 0, 86, 0, 73, 0, 34, 0, 86, 0, 104, 0, 55, 0, 53, 0, 67, 0, 61, 0, 88, 0, 49, 0, 63, 0, 91, 0, 78, 0, 38, 0, 62, 0, 87, 0, 68, 0, 54, 0, 100])

  Appendix to Proof #2 ends here.
*  
 */
